﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace BBICMS.Model.Validation
{
    public class IPAttribute      : RegularExpressionAttribute, IClientValidatable
    {
        public IPAttribute()
            : base(@"\d+\.\d+\.\d+\.\d+ ")
        {
        }

        public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
        {
            var errorMessage = FormatErrorMessage(metadata.GetDisplayName());

            yield return new IPValidationRule(errorMessage);
        }
    }
    public class IPValidationRule : ModelClientValidationRule
    {
        public IPValidationRule(string errorMessage)
        {
            ErrorMessage = errorMessage;
            ValidationType = "ip";
        }
    }
}